//
//  KZSwipViewController.m
//  xiaorizi
//
//  Created by kun on 15/10/23.
//  Copyright © 2015年 origin. All rights reserved.
//

#import "KZSwipViewController.h"
#import "KZBarTitle.h"
#import "UIViewAdditions.h"
#import "KZHorizonalViewController.h"
#import "KZEveryDayViewController.h"
#import "KZEveryDvdTableViewController.h"
#import "Masonry.h"

@interface KZSwipViewController ()

@property (nonatomic,weak) KZBarTitle *navigationBarTitles;

@property (nonatomic,weak) KZHorizonalViewController *horizonalViewController;


@end

@implementation KZSwipViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //self.view.backgroundColor = [UIColor yellowColor];
    //1设置navigationController
    [self addNavigationTitle];
    
    //2 添加视图控制器
    [self createhorizonalViewController];
    
}


- (void)createhorizonalViewController
{
   //1 添加控制器
    
    UIStoryboard *dvdVcSB = [UIStoryboard storyboardWithName:@"KZEveryDvdTableViewController" bundle:nil];

    KZEveryDayViewController *dayVc = [dvdVcSB instantiateViewControllerWithIdentifier:@"everyDay"];
    
    
       KZEveryDvdTableViewController *dvdVc = [dvdVcSB instantiateViewControllerWithIdentifier:@"everyDvd"];
    NSArray *arrayVc = @[dayVc,dvdVc];
    
    KZHorizonalViewController *horVc = [[KZHorizonalViewController alloc]init];
    horVc.controllers = arrayVc;
    
    [self.view addSubview:horVc.view];
   
    
    _horizonalViewController = horVc;
    
    //设置约束
    [horVc.view  mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@(64));
        make.left.equalTo(@(0));
        make.right.equalTo(@(0));
        make.bottom.equalTo(@(0));
    }];
    
    [self addChildViewController:self.horizonalViewController];
    
    
    //4 实现blokc事件 让title与 滑动视图控制器联动
    [_navigationBarTitles setTabbarTitleChange:^(UIButton * btn, NSInteger index) {
        
        CGFloat W =  self.view.frame.size.width;
        _horizonalViewController.collectionView.contentOffset = CGPointMake(W*index, 0);
    }];
    
    //滑动控制联动
    [_horizonalViewController setHorizonalViewChang:^(UIScrollView * view , NSInteger index) {
        
        //回调按键
        [_navigationBarTitles changeButtonWithIndex:index];
    }];
}

#pragma mark 给探店添加navigation标题说明
- (void)addNavigationTitle
{
    //1 navigation添加 图片说明
    KZBarTitle *barTitle = [[KZBarTitle alloc]initWithFrame:CGRectMake(0, 0,120,44) andTitles:@[@"美天",@"美辑"]];
    UIButton *button = [[UIButton alloc]init];
    button.frame = CGRectMake(0, 0, 40, 30);
    self.navigationItem.titleView = barTitle;
    _navigationBarTitles = barTitle;

}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
